#include <catch2/catch.hpp>

#include "solution.hpp"

using namespace solution_068;

TEST_CASE("068_text_justification", "[068]") {
    SECTION("example 1") {
        std::vector<std::string> words{"This", "is", "an", "example", "of", "text", "justification."};
        std::vector<std::string> lines{
            "This    is    an",
            "example  of text",
            "justification.  "
        };
        auto ans = Solution().fullJustify(words, 16);
        CHECK(ans.size() == lines.size());
        for (size_t i = 0; i < ans.size(); ++i)
            CHECK(ans.at(i) == lines.at(i));
    }

    SECTION("example 2") {
        std::vector<std::string> words{"What","must","be","acknowledgment","shall","be"};
        std::vector<std::string> lines{
            "What   must   be",
            "acknowledgment  ",
            "shall be        "
        };
        auto ans = Solution().fullJustify(words, 16);
        CHECK(ans.size() == lines.size());
        for (size_t i = 0; i < ans.size(); ++i)
            CHECK(ans.at(i) == lines.at(i));
    }

    SECTION("example 3") {
        std::vector<std::string> words{
            "Science","is","what","we",
            "understand","well",
            "enough","to","explain","to",
            "a","computer.",
            "Art","is",
            "everything","else","we",
            "do"
        };
        std::vector<std::string> lines{
            "Science  is  what we",
            "understand      well",
            "enough to explain to",
            "a  computer.  Art is",
            "everything  else  we",
            "do                  "
        };
        auto ans = Solution().fullJustify(words, 20);
        CHECK(ans.size() == lines.size());
        for (size_t i = 0; i < ans.size(); ++i)
            CHECK(ans.at(i) == lines.at(i));
    }

    SECTION("example 4") {
        std::vector<std::string> words{"do"};
        std::vector<std::string> lines{"do                  "};
        auto ans = Solution().fullJustify(words, 20);
        CHECK(ans.size() == lines.size());
        for (size_t i = 0; i < ans.size(); ++i)
            CHECK(ans.at(i) == lines.at(i));
    }

    SECTION("example 5") {
        std::vector<std::string> words{"do"};
        std::vector<std::string> lines{"do"};
        auto ans = Solution().fullJustify(words, 2);
        CHECK(ans.size() == lines.size());
        for (size_t i = 0; i < ans.size(); ++i)
            CHECK(ans.at(i) == lines.at(i));
    }
}
